//
//  HDXTypeView.m
//  test1
//
//  Created by henry on 16/10/30.
//  Copyright © 2016年 chen. All rights reserved.
//

#import "HDXTypeView.h"
#import "CZAdditions.h"
#import "Masonry.h"
@interface HDXTypeView ()
//按钮数组
@property(nonatomic,strong)NSMutableArray <UIButton*>*buttons;

@end





@implementation HDXTypeView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}


#pragma mark - 按钮点击事件
-(void)typeBtnClick:(UIButton *)button{
    switch (button.tag) {
        case 0:
            NSLog(@"点击了全类型");
            break;
        case 1:
            NSLog(@"点击了全时段");
            break;
        case 2:
            NSLog(@"点击了全价位");
            break;
        default:
            break;
    }
}


#pragma mark - 设置界面
-(void)setupUI
{
    //设置类型界面背景颜色
    self.backgroundColor = [UIColor whiteColor];
    
    //创建标题数组
    NSArray *titles = @[@"全类型",@"全时段",@"全价位"];
    //创建按钮数组
    self.buttons = [[NSMutableArray alloc]init];
    
    //定义索引下标
    NSInteger index = 0;
    
    for (NSString *title in titles) {
        //创建按钮
        UIButton *button = [UIButton cz_textButton:title fontSize:14 normalColor:[UIColor cz_colorWithHex:0x555555] selectedColor:[UIColor redColor]];
        //设置按钮的tag
        button.tag = index++;
        //添加按钮点击事件
        [button addTarget:self action:@selector(typeBtnClick:) forControlEvents:UIControlEventTouchDown];
        
        
        //将按钮添加到类型界面视图上
        [self addSubview:button];
        //将按钮添加到按钮数组
        [self.buttons addObject:button];
    }
    //对三个按钮进行自动布局
    [self.buttons[0] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self);
    }];
    
    [self.buttons[1] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttons[0].mas_right);
        make.top.equalTo(self);
        make.size.equalTo(self.buttons[0]);
    }];
    
    [self.buttons[2] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttons[1].mas_right);
        make.right.top.equalTo(self);
        make.size.equalTo(self.buttons[1]);
    }];


}


@end
